package password

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func checkCreatePassword(c *gin.Context) {
	password := c.Query("password")
	createPassword := MyPasswords.CreateBlog
	if createPassword == password {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"data": true,
		})
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"data": false,
		})
	}
}

func checkModifyPassword(c *gin.Context) {
	password := c.Query("password")
	adjustPassword := MyPasswords.ModifyBlog
	if adjustPassword == password {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"data": true,
		})
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"data": false,
		})
	}
}

func checkDeletePassword(c *gin.Context) {
	password := c.Query("password")
	deletePassword := MyPasswords.DeleteBlog
	if deletePassword == password {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"data": true,
		})
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"data": false,
		})
	}
}

func CheckBlogPassword(c *gin.Context) {
	operation := c.Query("operation")

	switch operation {
	case "create":
		checkCreatePassword(c)
	case "modify":
		checkModifyPassword(c)
	case "delete":
		checkDeletePassword(c)
	}
}
